package algotithm.interview.meituan.test4;

import java.io.*;

/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/20-16:53
 */
public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        String[] arr1 = reader.readLine().split(" ");
        int n = Integer.parseInt(arr1[0]);
        long m = Long.parseLong(arr1[1]);
        int[][] num = new int[n+1][n+1];
        int today = 2;
        int yestoday = 1;
        int tommorrer = 0;
        for (int i = 0; i < n; i++) {
            String[] arr = reader.readLine().split(" ");
            for (int j = 0; j < n; j++) {
                num[i][j] = Integer.parseInt(arr[j]);
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (num[i][j] != 0) {
                    tommorrer = num[i][j];
                    yestoday = j;
                    today = i;
                }
            }
        }
        long y = (m-2) % 3;
        int res = 0;
        if (m == 1) {
            res = 1;
        } else if (m == 2) {
            res = 2;
        }
        if (y == 0) {
            res = yestoday;
        } else if (y == 1) {
            res = today;
        } else {
            res = tommorrer;
        }

        writer.write(res + "\n");
        writer.flush();
        writer.close();
        reader.close();
    }

}
